package com.sensePlusVR.activity.mine;

import org.xutils.x;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sensePlusVR.base.BaseActivity;
import com.sensePlusVR.bean.UserDto;
import com.sensePlusVR.main.R;
import com.sensePlusVR.net.NetRequestManager;
import com.sensePlusVR.utils.AppManager;
import com.sensePlusVR.utils.Constant;
import com.sensePlusVR.utils.Constant.Sex;
import com.sensePlusVR.utils.MyLog;
import com.sensePlusVR.utils.MySharedPreferences;

/**
 * 
 * @author: Loren
 * @create: 2016-8-10下午2:43:36
 * @desc: 修改性别
 *
 */
@ContentView(R.layout.activity_setting_modify_sex)
public class ModifySexActivity extends BaseActivity implements OnClickListener{
	private static final String TAG = ModifySexActivity.class.getSimpleName();
	@ViewInject(R.id.title_bar_title_tv)
	private TextView title_bar_title_tv;
	
	@ViewInject(R.id.title_bar_right_tv)
	private TextView title_bar_right_tv;
	
	@ViewInject(R.id.male_iv)
	private ImageView male_iv;
	
	@ViewInject(R.id.female_iv)
	private ImageView female_iv;
	
	@ViewInject(R.id.male_relative)
	private RelativeLayout male_relative;
	
	@ViewInject(R.id.female_relative)
	private RelativeLayout female_relative;
	
	private UserDto userDto;
	
	@Override
	public void setMyContentView() {
		x.view().inject(this);
	}
	
	@Override
	public void initView() {
		super.initView();

		male_relative.setOnClickListener(this);
		female_relative.setOnClickListener(this);
		
		title_bar_title_tv.setText(R.string.modify_sex);
		title_bar_right_tv.setText(R.string.save);
		String userSex = MySharedPreferences.getString2(ModifySexActivity.this,MySharedPreferences.NAME_NOT_CLEAR, Constant.LOGIN_SUCCESS_SEX);
		MyLog.d(TAG, "userSex :" + userSex);
		
		if(userSex.equals(Sex.MALE) || userSex==null||userSex==""){
			visibleMale();
		}else if(userSex.equals(Sex.FEMALE)){
			visibleFemale();
		}
		userDto = new UserDto();
		AppManager.getInstance().addActivity(this);
		
	}
	
	@Event(value = {R.id.title_bar_left_ib,R.id.title_bar_right_tv})
	private void setViewOnClick(View view){
		switch (view.getId()) {
		case R.id.title_bar_left_ib:
			AppManager.getInstance().finishActivity(this);
			break;
		case R.id.title_bar_right_tv:
			NetRequestManager.startGetNewAccountInfo(ModifySexActivity.this, userDto);
			break;
		}
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.male_relative:
			Log.d(TAG, "male_relative");
			visibleMale();
			userDto.setSex("2");
			break;
		case R.id.female_relative:
			Log.d(TAG, "female_relative");
			visibleFemale();
			userDto.setSex("1");
			break;
		}
	}
	
	private void visibleMale(){
		male_iv.setImageResource(R.drawable.sex_select_men);
		female_iv.setImageResource(R.drawable.sex_unselect_femen);
	}
	
	private void visibleFemale(){
		female_iv.setImageResource(R.drawable.sex_select_femen);
		male_iv.setImageResource(R.drawable.sex_unselect_men);
	}

}
